package com.heima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.domain.pojo.QcCheckType;
import com.heima.mapper.CheckTypeMapper;
import com.heima.service.CheckTypeService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class CheckTypeServiceImpl extends ServiceImpl<CheckTypeMapper, QcCheckType> implements CheckTypeService {

    @Override
    public IPage<QcCheckType> queryPage(Page<QcCheckType> page, String code, String name) {
        LambdaQueryWrapper<QcCheckType> queryWrapper = new LambdaQueryWrapper<>();


        // 按名称模糊查询
        if (StringUtils.hasText(name)) {
            queryWrapper.like(QcCheckType::getName, name);
        }


//        if (code != null) {
        if (!ObjectUtils.isEmpty(code)) {
            queryWrapper.eq(QcCheckType::getCode, code);
        }


        queryWrapper.orderByAsc(QcCheckType::getId);

        return baseMapper.selectPage(page, queryWrapper);
    }

}
